// https://www.lintcode.com/problem/reorder-array-to-construct-the-minimum-number/description?_from=ladder&&fromId=6

bool cmp(const string s1, const string s2)
{
    return s1 + s2 < s2 + s1;
}
class Solution {
public:
    /**
     * @param nums: n non-negative integer array
     * @return: A string
     */
    string minNumber(vector<int> &nums) {
        vector<string> s_nums;
        string result = "";
        // stringstream stream;
        // for (int i = 0; i < nums.size(); ++i) {
        //     stream << nums[i];
        //     stream >> s_nums[i];
        //     stream.clear();
        // }
        for (int i = 0; i < nums.size(); ++i)
        {
            if (nums[i] != 0)
            s_nums.push_back(to_string(nums[i]));
        }
        if (s_nums.empty()) return "0";
        sort(s_nums.begin(), s_nums.end(), cmp);
        for (int i = 0; i < s_nums.size(); ++i)
        {
            result += s_nums[i];
        }
        return result;
    }
};